class Login{
    constructor(){
        this.user = document.querySelector('input[type=text]')
        this.pass = document.querySelector('input[type=password]')
        this.btn = document.querySelector('input[type=button]')
        this.init()
    }
    init(){
        this.cookieValue()   
        this.btnLog()
    }
    cookieValue(){
        if(getCookie('username') == undefined || getCookie('password')==undefined){
            this.user.value = ''
            this.pass.value = ''
        }else{
            this.user.value = getCookie('username')
            this.pass.value = getCookie('password')
        }
    }
    btnLog(){
        this.btn.onclick=()=>{
            if(this.user.value=='' || this.pass.value==''){
                alert('请输入账号密码')
                return
            }
            //判断注册的账号与登录的是否一致
            if(this.user.value == getCookie('username') || this.pass.value == getCookie('password')){
                setCookie('username',this.user.value)
                setCookie('password',this.pass.value)
                location.href = '/index.html'
            }else{
                alert('密码或账号不正确！')
            }
        }
    }
}
new Login()